<?php
/**
 * Created by PhpStorm.
 * User: 123
 * Date: 2020/7/27
 * Time: 15:23
 */

namespace app\service;

use phpmailer\BaseException;
use think\Db;


/**
 * 订单服务层
 * @author   juzi
 * @blog    https://blog.csdn.net/juziaixiao
 * @version  0.0.1
 * @datetime 2020年7月27日15:24:22
 */
class OrderService extends BaseService
{
    /**
     * 订单列表条件
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月24日13:22:12
     * @param    [array]          $params [输入参数]
     */
    public static function OrderListWhere($params = [])
    {

        $where = [];



        # 关键字搜索判断
        if(isset($params['orderdetail_status']) && $params['orderdetail_status'] ==1)
        {
            $where[] = ['mod.is_delete', '=', 2];

            $where[] = ['orderdetail_status', '=', intval($params['orderdetail_status'])];
            //关键词：手机号 订单号 收货人
            if(!empty($params['keywords']))
            {
                $where[] =['receive_phone|receive_name|order_number|bizpro_name', 'like', '%'.$params['keywords'].'%'];
            }
            //订单状态
            if(isset($params['order_status']) && $params['order_status'] > 0)
            {
                $where[] = ['mod.order_status', '=', intval($params['order_status'])];
            }
            if(!empty($params['province']))
            {
                $where[] = ['mo.province', '=', $params['province']];
            }
            if(!empty($params['city']))
            {
                $where[] = ['mo.city', '=', $params['city']];
            }
            if(!empty($params['mo.area']))
            {
                $where[] = ['area', '=', $params['area']];
            }

            //下单时间
            if(!empty($params['update_time']))
            {
                $where[] = ['mo.create_time', '>', date("Y-m-d 00:00:00",strtotime($params['update_time']))];
                $where[] = ['mo.update_time', '<',date("Y-m-d 23:59:59",strtotime($params['update_time']))];
            }
            //订单状态
            if(!empty($params['mod.order_status']))
            {
                $where[] = ['mod.order_status', '=', $params['order_status']];
            }

            // 金额区间
            if(!empty($params['price_start']))
            {
                $where[] = ['mo.pay_price', '>', $params['price_start']];
            }

            if(!empty($params['price_end']))
            {
                $where[] = ['mo.pay_price', '<', $params['price_end']];
            }

        }
        elseif(isset($params['order_data'])&&$params['order_data'] ==1)
        {
            $where[] = ['mod.is_delete', '=', 2];

            if(!empty($params ['keywords']))
            {
                $where[] =['receive_phone|bizpro_name', 'like', '%'.$params['keywords'].'%'];
            }

            if(isset($params['data_status']) && $params['data_status'] > 0)
            {
                //1 已下单 2未下单 3 已发货 4已完成
                switch ($params['data_status']){
                    case 1:
                        $where[] = ['mod.orderdetail_status', '=', 1];
                        break;
                    case 2:
                        $where[] = ['mod.orderdetail_status', '=', 2];
                        break;
                    case 3:
                        $where[] = ['mod.order_status', '=', 3];
                        break;
                    case 4:
                        $where[] = ['mod.order_status', '=', 4];
                        break;
                }
            }

            if(!empty($params['create_time']))
            {
                $where[] = ['mo.create_time', '>', $params['create_time']];
            }
        }
        else{
            //未删除
            $where[] = ['mo.is_delete', '=', 2];
            if(!empty($params['keywords']))
            {
                $where[] =['supplier_name', 'like', '%'.$params['keywords'].'%'];
            }

            // 状态
            if(isset($params['orderdetail_status']) && $params['orderdetail_status'] > 0)
            {
                $where[] = ['orderdetail_status', '=', intval($params['orderdetail_status'])];
            }
        }


        return $where;
    }
    /**
     * sql语句分类
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月22日10:57:35
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
    public static function OrderSqlCate($params)
    {
        $field=$params['field'];
        $where=$params['where'];
        $order_by=$params['order_by'];
        $group=$params['group'];

        // 获取数据
        if($params['mine']=='mineOrder'){
            #查询我的页 按类型查订单
            $data = Db::name('member_orderdetail')->alias('mod')->join(['member_order'=>'mo'], 'mo.id=mod.order_id')->field($field)->where($where)->order($order_by);
        }else  if($params['mine']=='express'){
            #查询物流 信息
            $data = Db::name('member_orderdetail')->alias('mod')->join(['member_order'=>'mo'], 'mo.id=mod.order_id')->join(['express'=>'e'], 'e.id=mod.logistic_id')->field($field)->where($where)->order($order_by);
        }else  if($params['mine']=='mineOrderList') {
            #查询物流 信息
            $data = Db::name('member_order mo')->field($field)->where($where)->order($order_by);
        } else{

            $data = Db::name('member_orderdetail')->alias('mod')
                ->leftJoin(['member_order'=>'mo'], 'mo.id=mod.order_id')
                ->leftJoin(['supplier'=>'s'], 's.id=mod.supplier_id')
                ->leftJoin(['member'=>'m'], 'm.id=mo.member_id')->field($field)->where($where)->order($order_by)->group($group);
        }
        return $data;
    }
    /**
     * 获取数据
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月22日10:57:35
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
    public static function OrderList($params = [])
    {
        $where = empty($params['where']) ? [['mod.order_id','>',0]] : $params['where'];
        $page = $params['page'] ? true : false;
        $number = isset($params['number']) ? intval($params['number']) : 10;
        $m = isset($params['m']) ? intval($params['m']) : 0;
        $n = isset($params['n']) ? intval($params['n']) : 0;
        $field = isset($params['field']) ? $params['field'] :'mod.*,md.*';
        $order_by = empty($params['order_by']) ? 'mod.id desc' : $params['order_by'];
        $group=isset($params['group']) ? $params['group'] : 'mod.id';
        // 获取sql
        $sql=self::OrderSqlCate(['where'=>$where,'order_by'=>$order_by,'field'=>$field,'mine'=>isset($params['mine'])?$params['mine']:'','group'=>$group]);

        //分页
        if($page)
        {
            $data=$sql->paginate($number, false, ['query' => request()->param()]);
            $data=$data->toArray()['data'];

            //dump($data->toArray());exit;
        }else{
            if($n)
            {
                $data=$sql->limit($m, $n)->select();
            }else{
                $data=$sql->select();

            }

        }
        return self::DataDealWith($data);



    }


    /**
     * 数据处理
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年7月21日13:29:33
     * @desc    description
     * @param   [array]          $data [广告数据 二维数组]
     */
    private static function DataDealWith($data){

        if(!empty($data) && is_array($data))
        {
            foreach($data as &$v)
            {

                if(isset($v['id']))
                {
                   $v['mod_id']= $v['id'];
                }


                if(isset($v['orderdetail_status']))
                {

                    $v['orderdetail_statustitle'] = intval($v['orderdetail_status'])==1 ? '已下单' : '未下单';
//                    if(isset($v['order_status']))
//                    {
//                        $v['data_status'] =  intval($v['orderdetail_status'])>intval($v['order_status']) ? $v['orderdetail_status']:$v['order_status'];
//                    }
                }


                //快递单号
                if(isset($v['express_code'])&&strlen($v['express_code'])<2)
                {
                    $v['express_code']='';

                }
                //var_dump($v);exit;
                //地址
                if(isset($v['address']))
                {
                    $v['address_all'] =  $v['province'] . $v['city'] .$v['area'] .$v['address'] ;
                }
                //dump($v);exit;
                //支付方式
                if(isset($v['pay_type']))
                {
                    $v['pay_type'] =  $v['pay_type']==1 ? '微信支付':'支付宝支付' ;
                }
                //订单状态
                if(isset($v['order_status']))
                {
                    if($v['order_status'] ==1){
                        $v['order_statustitle'] ='待付款';
                    }else if($v['order_status'] ==2){
                        $v['order_statustitle'] ='待发货';
                    }else if($v['order_status'] ==3){
                        $v['order_statustitle'] ='运输中';
                    }else if($v['order_status'] ==4){
                        $v['order_statustitle'] ='已完成';
                    }
                }
                //订单详情
                if(isset($v['mo_id']))
                {

                    //商品列表（缩略图 名称 标签 红色xl 数量 合计）

                    $v['bizpro_arr'] =  Db::name('member_orderdetail')->alias('mod')->leftJoin(['bizpro'=>'b'],'b.id=mod.bizpro_id')->where('order_id='.$v['mo_id'])->field('mod.bizpro_number,mod.id mod_id,mod.order_status,mod.orderdetail_status,b.bizpro_unit,mod.id id,bizpro_id,bizpro_imgurl,buy_num,price,bizpro_name,bizpro_lable,bizpro_spec_value,buy_num*price mod_total_price')->select();


                    //订单统计-列表-订单状态
                    $orderdetail_status_arr= Db::name('member_orderdetail')->where('order_id='.$v['mo_id'])->column('orderdetail_status');
                    sort($orderdetail_status_arr,1);
                    $orderdetail_status_min=$orderdetail_status_arr[0];
                    $order_status_arr= Db::name('member_orderdetail')->where('order_id='.$v['mo_id'])->column('order_status');
                    sort($order_status_arr,1);
                    $order_status_min=$order_status_arr[0];
                    $v['data_status']=self::HandleDataStatus($orderdetail_status_min,$order_status_min)[0];
//                    $v['data_status']=min($order_status_min,$orderdetail_status_min);
//                    if($orderdetail_status_min==2)
//                    {
//                        $v['data_status']= $order_status_min;
//                    }

                    $v['total_num']=0;
                    foreach ($v['bizpro_arr'] as &$bv)
                    {
                         //订单统计-详情-订单状态
                        $bv['bizpro_spec_value']=self::HandleSpec($bv['bizpro_spec_value']);
                        $bv['data_status']=self::HandleDataStatus($bv['orderdetail_status'],$bv['order_status'])[0];
                        $bv['data_statustitle']=self::HandleDataStatus($bv['orderdetail_status'],$bv['order_status'])[1];
                        $v['total_num']+=$bv['buy_num'];
                    }
                }

                if(isset($v['mod_id']))
                {

                    //商品详情
                    $v['bizpro'] =  Db::name('member_orderdetail')->where('id='.$v['mod_id'])->field('orderdetail_status,bizpro_id,bizpro_imgurl,buy_num,price,bizpro_name,bizpro_lable,bizpro_spec_value,buy_num*price mod_total_price,bizpro_number,order_status,send_time')->find();

                    $v['bizpro_spec_value']=self::HandleSpec($v['bizpro']['bizpro_spec_value']);

                    $v['bizpro']['data_status']=self::HandleDataStatus($v['bizpro']['orderdetail_status'],$v['bizpro']['order_status'])[0];

                    //确认收货状态修改
                    if($v['bizpro']['order_status']!=4&&strtotime($v['bizpro']['send_time'],'+'.config('leebridge.auto_recept_days'))< TIMESTAMP)
                    {
                        Db::name('member_orderdetail')->where('id='.$v['mod_id'])->update(['order_status'=>4]);
                    }

                }

                # 物流信息
                if(isset($v['logistic_id']))
                {

                    $v['logistic_title'] =  Db::name('express')->where('id='.$v['logistic_id'])->value('title');
                }



                #查商品数量
//                if(isset($v['bizpro_id']))
//                {
//                    $v['bizpro_num'] = Db::name('member_orderdetail')->where([['is_delete','=',2],['order_status','>',1],['bizpro_id','=',$v['bizpro_id']]])->count();
//                }

            }

           // dump($data);exit;
        }

        return DataReturn('获取成功',0,$data);
    }
    /**
     * 处理规格
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年7月21日13:29:33
     * @desc    description
     * @param    [int]          $orderdetail_status [1已下单 2未下单]
     * @param    [int]          $orderdetail_status [1已下单 2未下单]
     */
    public static function HandleDataStatus($orderdetail_status,$order_status){
        $data_status=min($orderdetail_status,$order_status);
        if($orderdetail_status==2)
        {
            $data_status= $order_status;
        }
        if($data_status ==1){
            $data_statustitle ='已下单';
        }else if($data_status ==2){
            $data_statustitle ='未下单';
        }else if($data_status ==3){
            $data_statustitle ='已发货';
        }else if($data_status ==4){
            $data_statustitle ='已完成';
        }
        return [$data_status,$data_statustitle];
    }

    /**
     * 处理规格
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年7月21日13:29:33
     * @desc    description
     * @param    [array]          $where [条件]
     */
    public static function HandleSpec($spec_value)
    {
        $re= json_decode($spec_value,true);

        $spec_value_new = !empty($re) ? implode(",",$re) : '';
        if(substr($spec_value_new,strlen($spec_value_new)-1)==',')
        {
            $spec_value_new=substr($spec_value_new,0,strlen($spec_value_new)-1);
        }
        return $spec_value_new;
    }

    /**
     * 总数
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年7月21日13:29:33
     * @desc    description
     * @param    [array]          $where [条件]
     */
    public static function DataTotal($group,$where)
    {
        $group=empty($group) ? 'mod.id' :$group ;
        $data = Db::name('member_orderdetail')->alias('mod')
            ->leftJoin(['member_order'=>'mo'], 'mo.id=mod.order_id')
            ->leftJoin(['supplier'=>'s'], 's.id=mod.supplier_id')
            ->leftJoin(['member'=>'m'], 'm.id=mo.member_id')
            ->where($where)->group($group)->count();

        return (int) $data;
    }

    /**
     * 总数
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年7月21日13:29:33
     * @desc    description
     * @param    [array]          $where [条件
     */
    public static function ToSendDataTotal($where=[]){
        $where=empty($where)?['mo.order_status'=>2,'mo.is_delete'=>2,'mo.pay_status'=>1]:$where;
        $data = [];
        //待发货金额(进价)
        $data['tosendprice']=0.00;
        //待发货金额（售价）
        $data['tosendprice_total']=0.00;
        $all=Db::name('member_orderdetail')->alias('mod')
            ->join(['member_order'=>'mo'], 'mo.id=mod.order_id')->join(['supplier'=>'s'], 's.id=mod.supplier_id')
            ->where($where)->field('mod.price,mod.buy_num,price,buy_price')->select();
        //dump($all);exit;
        if(count($all)>0){
            foreach ($all as $v)
            {
                $data['tosendprice']+= $v['buy_price']*$v['buy_num'];
                $data['tosendprice_total']+= $v['price']*$v['buy_num'];
            }
        }

            //->sum('mod.buy_price*mod.buy_num');
        $data['tosendprice']=number_format($data['tosendprice'],'2');
        $data['tosendprice_total']=number_format($data['tosendprice_total'],'2');
        //
        //代发货商品种类
        $data['tosendcate']=Db::name('member_orderdetail')->alias('mod')->join(['member_order'=>'mo'], 'mo.id=mod.order_id')->join(['supplier'=>'s'], 's.id=mod.supplier_id')->join(['bizpro'=>'b'], 'b.id=mod.bizpro_id')->where(['mo.order_status'=>2,'mo.is_delete'=>2,'mo.pay_status'=>1])->group('b.class_pid')->count();
        //代发货数量
        $data['tosendnum']=Db::name('member_orderdetail')->alias('mod')->join(['member_order'=>'mo'], 'mo.id=mod.order_id')->where(['mod.order_status'=>2,'mod.is_delete'=>2,'mo.pay_status'=>1])->count();


        return  $data;
    }


    /**
     * 数据校验
     * @author   juzi
     * @blog     https://blog.csdn.net/juziaixiao
     * @version  1.0.0
     * @datetime  2020年7月23日12:06:23
     * @param    [array]          $params [输入参数]
     */
    public static function VaryData($params){
        // 公共数据校验请求参数
        $p = [


            [
                'checked_type' => 'empty',
                'key_name' => 'buy_num',
                'error_msg' => '商品数量不能为空',
                'error_code' => 4001,
            ],
            [
                'checked_type' => 'empty',
                'key_name' => 'price',
                'error_msg' => '价格不能为空',
                'error_code' => 4002,
            ],



        ];

        $ret=ParamsChecked($params, $p);

        if(true !== $ret)
        {
            //$error_arr[0]  $error_arr[1]
            $error_arr = explode(',', $ret);
            throw new BaseException(['code'=>403 ,'errorCode'=>$error_arr[1],'msg'=>$error_arr[0],'status'=>false,'debug'=>false ]);
        }
        return true;

    }


    /**
     * 位置重复判断
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年7月21日15:20:43
     * @desc    description
     * @param   [array]          $params [输入参数]
     */
    public static function CheckTitle($params){
        $data = Db::name($params['table'])->where($params['where'])->find();
        $cond1=!empty($data)&&empty($params['params']['id']);
        $cond2=!empty($data)&&isset($params['params']['id'])&&intval($data['id'])!=$params['params']['id'];
        $error=0;
        //添加数据
        if($cond1)
        {

            $error=1;
        }
        //编辑数据
        if($cond2)
        {
            //统一分类下 名称不得相同
            if($data['pid']==$params['params']['pid'])
            {
                $error=1;
            }
        }
        if($error)
        {
            throw new BaseException(['code'=>403 ,'errorCode'=>$params['error_code'],'msg'=>$params['msg'],'status'=>false,'debug'=>false]);

        }
        return true;
    }



    /**
     * 修改member_order
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年7月21日15:20:43
     * @desc    description
     * @param   [array]          $data [输入参数]
     */
    public static function SaveOrder($data)
    {


        Db::startTrans();
        $data['update']['update_time'] = TIMESTAMP;
        //dump( $data);exit;
        $re = Db::name($data['table'])->where($data['where'])->update($data['update']);

//        if (!$re) {
//            Db::rollback();
//            throw new BaseException(['code' => 403, 'errorCode' => $data['errorCode'], 'msg' => $data['msg'], 'status' => false, 'debug' => false]);
//        }
        Db::commit();
        return true;
    }

    /**
     *  数据处理
     * @author   juzi
     * @blog     https://blog.csdn.net/juziaixiao
     * @version  1.0.0
     * @datetime 2020年7月10日11:08:21
     * @param    [array]          $params [输入参数]
     */
    public function HandleData(){

    }
    /**
     * [getCheckOrder 立即下单 ]
     * @Content 数据处理
     * @param  array()
     */
    function getCheckOrder($info,$shopcarId,$memberId){

        if(!empty($info)){
            #默认total_num = 1 商品数量 指的是 订单详情中有几种商品
            $total_num = 1;

            if(!empty($shopcarId)){
                # 购物车id集合
                $shopcar_id = implode(',',$shopcarId);
                $total_num = input("post.total_num")?input("post.total_num"):0;
            }
            #当前时间
            $create_time = date('Y-m-d H:i:s');
            $total_price = 0;
            $order_array = array();

            #创建订单 购物车结算|立即购买
            $getOrderNumber = getOrderNumber();
            $order_id = Db::table('member_order')->insertGetId(array(
                'order_number'=>$getOrderNumber,
                'member_id'=>$memberId,
                'create_time' =>$create_time,
                'total_price'=>$total_price,
                'total_num'=>$total_num,
            ));

            if(is_null($shopcarId) or empty($shopcarId)){
                # 规格

                $spec=[];
                if(isset($info['standard_value1']))
                {
                    $spec['standard_value1'] =  $info['standard_value1'];
                }
                if(isset($info['standard_value2']))
                {
                    $spec['standard_value2'] =  $info['standard_value2'];
                }
                if(isset($info['bizpro_id'])){
                    #获取进货价格
                    $standard_detail=$spec;
                    $standard_detail['bizpro_id']=$info['bizpro_id'];
                    $pursh_price= BizproService::StandardPrice($standard_detail);
                }
                #订单详情
                array_push($order_array,array(
                    'order_id'=>$order_id,

                    'bizpro_id'=>$info['bizpro_id'],
                    'buy_num'=>$info['buy_num'],
                    'price'=>$info['price'],
                    'create_time'=>$create_time,
                    'bizpro_imgurl'=>$info['bizpro_imgurl'],
                    'bizpro_name'=>$info['bizpro_name'],
                    'bizpro_number'=>$info['bizpro_number'],
                    'bizpro_lable'=>implode(',',$info['bizpro_lable']),
                    'supplier_id'=>$info['supplier_id'],
                    'buy_price'=>$pursh_price['data']['buy_price'],
                    'bizpro_spec_value'=>empty($spec) ? '' : json_encode($spec),
                ));

                #修改总价
                Db::table('member_order')->where(array('id'=>$order_id))->setInc('total_price',$info['buy_num']*$info['price']);
                #订单详情插入
                Db::table('member_orderdetail')->insertAll($order_array);

            }else{
                #命名为空数组
                $shop_array=array();
                #查询购物车信息
                $shopcar  = Db::table('member_cart')->where("id in (" .$shopcar_id. ")")->select();
                if(!empty($shopcar)){

                    foreach ($shopcar as $k=>$v){
                        //进货价格
                        $standard_detail=json_decode($v['bizpro_spec_value'],true);
                        $standard_detail['bizpro_id']=$v['bizpro_id'];
                        $standard_price= BizproService::StandardPrice($standard_detail);
                        $buy_price=$standard_price['data']['buy_price'];

                        array_push($shop_array,array('order_id'=>$order_id,
                            'bizpro_id'=>$v['bizpro_id'],
                            'buy_num'=>$v['buy_num'],
                            'price'=>$v['bizpro_saleprice'],
                            'create_time'=>$create_time,
                            'bizpro_imgurl'=>$v['bizpro_imgurl'],
                            'bizpro_name'=>$v['bizpro_name'],
                            'bizpro_number'=>$v['bizpro_number'],
                            'bizpro_lable'=>implode(',',json_decode($v['bizpro_label'])),
                            'supplier_id'=>$v['supplier_id'],
                            'bizpro_spec_value'=>$v['bizpro_spec_value'],
                            'buy_price'=>$buy_price,
                            ));
                        #修改总价
                        Db::table('member_order')->where(array('id'=>$order_id))->setInc('total_price',$v['buy_num']*$v['bizpro_saleprice']);
                    }
                    $res = Db::table('member_orderdetail')->insertAll($shop_array);
                }
                #如果是购物车 清除购物车
                Db::table('member_cart')->where("id in ($shopcar_id)")->delete();
            }
        }
        #返回  订单id
        return $order_id;


    }


    /**
     *  数据处理
     * @author   juzi
     * @blog     https://blog.csdn.net/juziaixiao
     * @version  1.0.0
     * @datetime 2020年7月10日11:08:21
     * @param    [array]          $params [输入参数]
     */
    public static function SaveSerInfo($params){
        # 用户状态查询
        MemberService::MemberStatusCheck('id', $params['member_id']);

        #用户跟订单关系判断
        $field='mo.id mo_id';

        $data_params = [
            'm' => 0,
            'n' => 1,
            'page' => false,
            'where' => ['mo.id' => intval($params['order_id']),'member_id'=>$params['member_id']],
            'field'=>$field,
        ];
        // 查询用户状态是否正常
        $ret=self::OrderList($data_params);

        if($ret['code']!=0)
        {
            throw new BaseException(['code'=>403 ,'errorCode'=>4005,'msg'=>'订单信息错误','status'=>false,'debug'=>false ]);
        }

        #修改member order
        $data['where']=['id'=>$params['order_id']];
        $data['update']=['is_delete'=>1];
        $data['table']='member_order';
        $data['msg']='修改订单失败';
        $data['errorCode']='4004';

        self::SaveOrder($data);
        #修改member detail
        $data1['where']=['order_id'=>$params['order_id']];
        $data1['update']=['is_delete'=>1];
        $data1['table']='member_orderdetail';
        $data1['msg']='修改订单详情失败';
        $data1['errorCode']='4003';

        self::SaveOrder($data1);

        return true;
    }

    /**
     *  供应商款项处理：结款+应付
     * @author   juzi
     * @blog     https://blog.csdn.net/juziaixiao
     * @version  1.0.0
     * @datetime 2020年9月16日09:32:20
     * @param    [array]          $params [输入参数]
     */
    public static function SaveSupPrice($params){
        $id=$params['id'];
        //dump($id);exit;
        $memberOdrderDetail = Db::table("member_orderdetail")->field('id,supplier_id,(buy_num*buy_price) total_price')->where("id = $id")->find();
        //判断供应商结款是否存在-》不存在则添加，存在则更新(更新应结款金额和累计销售金额)
        $spplier_fee=Db::table('supplier_fee')->where('supplier_id='.$memberOdrderDetail['supplier_id'])->find();
        if(empty($spplier_fee))
        {
            Db::table('supplier_fee')->insert(array(
                    'supplier_id'=>$memberOdrderDetail['supplier_id'],
                    'pay_price'=>$memberOdrderDetail['total_price'],
                    'total_price'=>$memberOdrderDetail['total_price']

            ));
        }else{
            Db::table('supplier_fee')->where('supplier_id='.$memberOdrderDetail['supplier_id'])->setInc('total_price',$memberOdrderDetail['total_price']);
            Db::table('supplier_fee')->where('supplier_id='.$memberOdrderDetail['supplier_id'])->setInc('pay_price',$memberOdrderDetail['total_price']);
        }
    }
}